<template>
	<view class="shopping_type">
		<view class="close" @click="$emit('close')">
			<image :src="`${baseImageUrl}/common/close1.png`"></image>
		</view>
		<view class="info">
			<image :src="cover" class="cover"></image>
			<view class="info_view">
				<view class="name">{{name}}</view>
				<view class="stock">数量：1</view>
				<!-- <view class="stock">库存：{{stock}}</view> -->
			</view>
		</view>
		<!-- <view class="title">数量</view>
		<view class="number_box">
			<view class="icon" @click="reduce">
				<image :src="`${baseImageUrl}/common/js.png`"></image>
			</view>
			<input type="text" placeholder="购买数量" v-model="number" @input="change_number">
			<view class="icon" @click="add">
				<image :src="`${baseImageUrl}/common/zj.png`"></image>
			</view>
		</view> -->
		<view class="btn_view">
			<view class="confirm" @click="confirm">确认选择</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			cover: {
				type: String,
				default: ""
			},
			name: {
				type: String,
				default: ""
			},
			stock: {
				type: [Number, String],
				default: ""
			}
		},
		data() {
			return {
				number: 1
			}
		},
		methods: {
			reduce() {
				if (this.number == 0) {
					this.$u.toast("不可减少了");
					return false;
				}
				this.number--;
			},
			add() {
				if (this.number >= this.stock) {
					this.$u.toast("不可增加了");
					return false;
				}
				this.number++;
			},
			change_number(e) {
				e.target.value = e.target.value.replace(/^0|[^\d]|[.]/g, "");
				this.$nextTick(() => {
					this.number = e.target.value;
				});
			},
			confirm() {
				if (this.number <= 0) {
					this.$u.toast("请输入购买数量");
					return false;
				}
				if (this.number >= this.stock) {
					this.$u.toast("库存数量不足");
					return false;
				}
				this.$emit("confirm", this.number);
			}
		}
	}
</script>

<style scoped lang="scss">
	.shopping_type {
		height: 606rpx;
		padding: 40rpx;
		box-sizing: border-box;
		background: url(#{$baseImageUrl}/bg/688_606.png) no-repeat;
		background-size: 100% 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		position: relative;

		.close {
			width: 122rpx;
			height: 122rpx;
			position: absolute;
			right: 0rpx;
			top: 0rpx;
			transform: translate(30rpx, -50rpx);
			z-index: 2;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.info {
			display: flex;

			.cover {
				width: 210rpx;
				height: 210rpx;
				border-radius: 10rpx;
			}

			.info_view {
				flex: 1;
				height: 210rpx;
				padding-left: 40rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				overflow: hidden;

				.name {
					color: #494338;
					font-size: 36rpx;
					font-weight: 400;
					font-family: LiSu;
				}

				.stock {
					color: #494338;
					font-size: 28rpx;
					font-family: SimSun;
					font-weight: 400;
				}
			}
		}

		.number_box {
			height: 80rpx;
			// margin: 36rpx 0 60rpx;
			// margin: 18rpx 0 30rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			display: flex;

			.icon {
				width: 80rpx;
				height: 80rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			input {
				flex: 1;
				height: 80rpx;
				text-align: center;
				color: #494338;
				font-size: 50rpx;
				font-weight: 400;
				font-family: SimSun;
				border-radius: 10rpx;
				box-shadow: 2rpx -1rpx 10rpx 0px rgba(3, 0, 0, 0.2);
				padding-left: 40rpx;
				box-sizing: border-box;
				background: #C0B5B6;
			}
		}

		.btn_view {
			width: 100%;
			display: flex;
			justify-content: center;

			view {
				width: 370rpx;
				height: 140rpx;
				line-height: 140rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: SimSun;
			}

			.cancel {
				background: url(#{$baseImageUrl}/common/btn2.png) no-repeat;
				background-size: 100% 100%;
			}

			.confirm {
				background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
				background-size: 100% 100%;
			}
		}
	}
</style>